package com.ruoyi.logistic.service.impl;

import com.ruoyi.logistic.domain.NetworkClient;
import com.ruoyi.logistic.domain.NetworkClientAndTag;
import com.ruoyi.logistic.domain.NetworkClientTag;
import com.ruoyi.logistic.mapper.NetworkClientAndTagMapper;
import com.ruoyi.logistic.mapper.NetworkClientMapper;
import com.ruoyi.logistic.service.NetworkClientAndTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class NetworkClientAndTagServiceImpl implements NetworkClientAndTagService {
    @Autowired
    private NetworkClientAndTagMapper networkClientAndTagMapper;
    @Autowired
    private NetworkClientMapper networkClientMapper;
    @Override
    public List<NetworkClientAndTag> selectAll() {
        return networkClientAndTagMapper.selectAll();
    }

    @Override
    public Boolean insert(NetworkClientAndTag networkClientAndTag) {
        return networkClientAndTagMapper.insert(networkClientAndTag);
    }

    @Override
    public Boolean update(NetworkClientAndTag networkClientAndTag) {
        return networkClientAndTagMapper.update(networkClientAndTag);
    }

    @Override
    public Boolean deleteById(Integer id) {
        return networkClientAndTagMapper.deleteById(id);
    }

    @Override
    public List<NetworkClientAndTag> findByClientId(Integer clientId) {
        return networkClientAndTagMapper.findByClientId(clientId);
    }

    @Override
    public String findByClient(Integer clientId) {
        List<NetworkClientAndTag> clientAndTagList = networkClientAndTagMapper.findByClientId(clientId);
        String result = clientAndTagList.stream()
                .map(NetworkClientAndTag::getNetworkClientTags)
                .flatMap(List::stream)
                .map(NetworkClientTag::getTagName)
                .collect(Collectors.joining(","));
        return result;
    }

    @Override
    public List<NetworkClient> findBigClient() {
        return networkClientMapper.findBigClient();
    }
}
